<%@page import="edu.facilities.utils.Format"%>
<%@page import="edu.facilites.model.FacilitiesInfo"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>体育设施预约系统-设备管理</title>
        <link href="css/style.css" rel="stylesheet" type="text/css" />
        <script src="js/jquery-1.6.2.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                $("#_selectfacilities").click(function () {
                    $("#_type").val("select");//查询按钮点击后类型为select
                    $("#_form1").submit();
                });
                $("#_adddiv").hide();
                $("#_addfacilitiesinfo").click(function () {
                    $("#_adddiv").show();
                    $("#_type").val("add");
                });
                $("._delfacilitiesinfo").each(function() {
                   $(this).click(function() {
                       if(confirm("确定删除吗？")) {
                            $("#_type").val("del");
                            $("#_facilitiesinfoid").val($(this).attr("val"));
                            $("#_form1").submit();
                       }
                   });
                });
                
                var usertype = "<%=Format.null2Blank(request.getAttribute("facilitiestype"))%>";
                $("select[@name='facilitiesTypeId'] option").each(function() {
                   if($(this).attr("value") == usertype) {
                       $(this).attr("selected", "selected");
                   } 
                });
            });
        </script>
    </head>

    <body>
        <h1>
            <a>体育设施预约系统</a>
        </h1>
        <p class="man">您好：<%=request.getSession().getAttribute("userName")%></p>
        <div class="man-list">
            <jsp:include page="/WEB-INF/jsp/leftFrame.jsp" />
            <!-- InstanceBeginEditable name="EditRegion1" --> 
            <form id="_form1" action="<%=request.getContextPath()%>/facilitiesManager.do" method="post">
                <p class="r-1">
                    设备类型：<select name="facilitiesTypeId">
                                <option value="1">篮球室</option>
                                <option value="2">羽毛球室</option>
                                <option value="3">乒乓球室</option>
                            </select>
                    <input type="button" id="_selectfacilities" value="查询" style="margin-left: 10px;width:80px;height: 40px;"/>
                    <input type="button" id="_addfacilitiesinfo" value="添加设备" style="margin-left: 30px;width:80px;height: 40px;margin-right: 15px;"/>
                    <%
                               String msg = Format.null2Blank(request.getAttribute("errorMsg"));
                               if(msg.length() > 0) {
                                   StringBuilder sb = new StringBuilder();
                                   sb.append("(<span style='color:red'>");
                                   sb.append(msg);
                                   sb.append("</span>)");
                                   out.print(sb.toString());
                               }        
                            %>
                </p>
                <div class="man-right">
                    <div class='r-1-bot' id="_adddiv">
                        <input type="hidden" name="_type" id="_type" value="" />
                        <p class="r-1-bot">设备名称：<input type="text" name="_name" maxlength="50"/><select name="_facilitiestype">
                                <option value="1">篮球室</option>
                                <option value="2">羽毛球室</option>
                                <option value="3">乒乓球室</option>
                            </select><input type="submit" style="margin-left: 15px;" value="添加"/></p> 
                    </div>
                    
                            
                    <%
                        String type = Format.null2Blank(request.getAttribute("type"));
                        StringBuilder sb = new StringBuilder();
                        try {
                            List<FacilitiesInfo> list = (List<FacilitiesInfo>) request.getAttribute("facilitiesList");
                            sb.append("<div class='r-1-bot'>");
                            sb.append("<p class='r-1-name'>序号</p>");
                            sb.append("<p class='r-1-name'>设备名称</p>");
                            sb.append("<p class='r-1-name'>操作</p>");
                            sb.append("</div>");
                            int flag = 1;
                            for (FacilitiesInfo facilitiesinfo : list) {
                                sb.append("<div class='r-1-bot'>");
                                sb.append("<p class='r-1-name'>");
                                sb.append(flag ++);
                                sb.append("</p>");
                                sb.append("<p class='r-1-name'>");
                                sb.append(facilitiesinfo.getName());
                                sb.append("</p>");
                                sb.append("<p class='r-1-name'><button class='_delfacilitiesinfo' val='");
                                sb.append(facilitiesinfo.getId());
                                sb.append("'>删除</button></p>");
                                sb.append("</div>");
                            }
                        } catch (Exception e) {
                        }
                        out.print(sb.toString());
                    %>
                    <input type="hidden" value="" name="_facilitiesinfoid" id="_facilitiesinfoid"/>
                </div>
            </form>
        </div>
    </body>
</html>


